#!/bin/bash
cd `dirname $0`

if [ "$1" == "" ]; then
 VERSION=3
 echo No version given, assuming Pi$VERSION
else
 VERSION=$1
fi

BRDIR=`./brdir $VERSION`
echo "Building updater from $BRDIR"

if [ "$2" != "" ]; then
  echo "Using timestamp $2"
  TS=$2
else
  TS=`date +%Y%m%d`
fi

cd `dirname $0`
MYDIR=`pwd`
TMPDIR=/tmp/$$
mkdir $TMPDIR
cp $BRDIR/images/*Image $BRDIR/images/rootfs.* $TMPDIR
pushd $TMPDIR
ls $TMPDIR
pwd
ls
cp $MYDIR/scripts/updater.sh .
tar cvfz $MYDIR/images/updater-$TS-pi$VERSION.tar.gz updater.sh *Image rootfs.ext2
zip $MYDIR/images/updater-$TS-pi$VERSION.zip updater.sh *Image rootfs.ext2
popd
rm -rf $TMPDIR
